package org.itboys.pay.weixin;

import org.itboys.commons.utils.encryption.Digests;
import org.itboys.commons.utils.random.RandomUtils;

/**
 * Created by Administrator on 2016/10/24.
 */
public class AppPaySignTool {

    private String appid;//应用号
    private String partnerid;//商户id
    private String prepayid;//预支付交易会话ID
    private String package_;
    private String noncestr;
    private String timestamp;
    private String sign;

    public AppPaySignTool(){}

    public AppPaySignTool(String appid, String partnerid, String prepayid, String key){
        this.appid = appid;
        this.partnerid = partnerid;
        this.prepayid = prepayid;
        this.timestamp = Long.toString(System.currentTimeMillis()/1000);
        this.noncestr = RandomUtils.getClearRandomStr(16);
        this.package_="Sign=WXPay";
        String param = "appid="+this.appid+"&noncestr="+this.noncestr+"&package="+this.package_
                +"&partnerid="+this.partnerid+"&prepayid="+this.prepayid+"&timestamp="+this.timestamp+"&key="+key;

        String param3 = "appid=" + this.appid + "&noncestr=" + this.noncestr + "&package=" + this.package_ + "&partnerid=" + partnerid + "&prepayid=" + this.prepayid + "&timestamp=" + this.timestamp + "&key=" + key;
        System.out.print("++++++++++++++++++++++param3+++"+param3);


       //this.sign = Digests.md5(param).toUpperCase();
        this.sign= Digests.md5(param3).toUpperCase();
    }

  /*  public AppPaySignTool(String appid, String partnerid, String prepayid, String package_, String noncestr, String timestamp, String sign) {
        this.appid = appid;
        this.partnerid = partnerid;
        this.prepayid = prepayid;
        this.package_ = package_;
        this.noncestr = noncestr;
        this.timestamp = timestamp;
        this.sign = sign;
    }*/

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getPartnerid() {
        return partnerid;
    }

    public void setPartnerid(String partnerid) {
        this.partnerid = partnerid;
    }

    public String getPrepayid() {
        return prepayid;
    }

    public void setPrepayid(String prepayid) {
        this.prepayid = prepayid;
    }

    public String getPackage_() {
        return package_;
    }

    public void setPackage_(String package_) {
        this.package_ = package_;
    }

    public String getNoncestr() {
        return noncestr;
    }

    public void setNoncestr(String noncestr) {
        this.noncestr = noncestr;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }
}
